//
//  main.c
//  6 chapter
//
//  Created by edz on 2020/6/28.
//  Copyright © 2020 edz. All rights reserved.
//

#include <stdio.h>


#if 0
// 作业1:计算长方体体积的函数
double cuboid(double length, double width, double height){
    double v;
    v = length * width * height;
    return v;
}

int main(){
    double length, width, height;
    printf("输入长方体的长宽高：\n");
    printf("长：");
    scanf("%lf",&length);
    printf("宽：");
    scanf("%lf",&width);
    printf("高：");
    scanf("%lf",&height);
    printf("这个长方体体积为%lf\n",cuboid(length, width, height));
    return 0;
}
#endif


#if 0
// 作业2:计算第n项斐波拉契数列的函数
int fib(int n){
    int x,x1,x2;
    x1 = x2 = 1;
    x = 0;
    if (n<=2) {
        return 1;
    }
    else{
        for (int i = 3; i <= n; i++) {
            x = x1 + x2;
            x1 = x2;
            x2 = x;
        }
        return x;
    }
}

int main(){
    int n;
    printf("输入一个正整数：");
    scanf("%d",&n);
    printf("第%d项斐波拉契数列的数是：%d\n",n,fib(n));
    return 0;
}
#endif


#if 0
// 作业3:计算三个数中最大值的函数
int max(int a, int b, int c){
    int max;
    max = a;
    if (max < b) {
        max = b;
    }
    if (max < c) {
        max = c;
    }
    return max;
}

int main (){
    int a,b,c;
    printf("请输入三个整数：");
    scanf("%d%d%d",&a,&b,&c);
    printf("这三个数中最大的数是：%d\n",max(a, b, c));
}
#endif

#if 0
// 作业4 大小写转换
void characters(void);

int main(){
    characters();
    return 0;
}

void characters(void){
    char ch;
    while ((ch = getchar()) != '\n') {
        if (ch >= 'A' && ch <= 'Z') {
            ch = ch + 'a' - 'A';
        }
        if (ch >= 'a' && ch <= 'z') {
            ch = ch + 'A' - 'a';
        }
        putchar(ch);
    }
    printf("\n");
}
#endif

#if 0
// 练习6-1
int min2(int a , int b);

int main(int argc, const char * argv[]) {
    int a , b;
    printf("请输入两个整数：\n");
    printf("整数A：");
    scanf("%d",&a);
    printf("整数B：");
    scanf("%d",&b);
    printf("较小的数是%d\n",min2(a, b));
    return 0;
}

int min2(int a , int b){
    if (a<b) {
        return a;
    }
    else
        return b;
}
#endif


#if 0
// 练习6-2
int min3(int a,int b,int c);

int main(){
    int a , b , c;
    printf("请输入三个整数：\n");
    printf("整数A：");
    scanf("%d",&a);
    printf("整数B：");
    scanf("%d",&b);
    printf("整数C：");
    scanf("%d",&c);
    printf("三个数中最小的值是%d\n",min3(a,b,c));
    return 0;
}


int min3(int a,int b,int c){
    int min;
    min = a < b ? (a < c ? a : c) : (b < c ? b : c);
    return min;
}
#endif


#if 0
// 练习6-3
int cube(int x);

int main(){
    int x;
    printf("请输入一个整数：");
    scanf("%d",&x);
    printf("这个数的三次方是%d\n",cube(x));
    return 0;
}

int cube(int x){
    x = x * x * x;
    return x;
}
#endif


#if 0
// 练习6-4
int pow4(int x);

int main(){
    int x;
    printf("请输入一个整数：");
    scanf("%d",&x);
    printf("这个数的四次幂是%d\n",pow4(x));
    return 0;
}

int pow4(int x){
    x = x * x * x * x;
    return x;
}
#endif


#if 0
// 练习6-5
int sumup(int n);
int main(){
    int n;
    printf("请输入一个整数：");
    scanf("%d",&n);
    printf("从1到%d的整数和为%d\n",n,sumup(n));
    return 0;
}

int sumup(int n){
    int sum=0;
    for (int i = 0; i<= n; i++) {
        sum = sum + i;
    }
    return sum;
}
#endif

#if 0
// 练习6-6
void alert(int n){
    for (int i = 0; i < n; i++) {
        printf("\a");
    }
}
#endif


#if 0
// 练习6-7
void hello(void){
    printf("你好。\n");
}
#endif


#if 0
// 练习6-8
int min_of(const int v[],int n){
    int min = v[0];
    for (int i = 0; i < n; i++) {
        if (v[i] < min) {
            min = v[i];
        }
    }
    return min;
}
#endif


#if 0
// 练习6-9
void rev_intary(int v[],int n){
    int temp = 0;
    for (int i=0; i < n/2.0; i++) {
        temp = v[i];
        v[i] = v[n-i-1];
        v[n-i] = temp;
    }
}
#endif


#if 0
// 练习6-10
void intary_rcpy(int v1[],const int v2[],int n){
    int i,j = 0;
    for (i = n-1; i >= 0; i--) {
        v1[j] = v2[i];
        j++;
    }
}
#endif


#if 0
// 练习6-11
int search_idx(const int v[],int idx[],int key,int n){
    int count = 0;
    int j = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] == key) {
            count++;
            idx[j] = i;
            j++;
        }
    }
    return count;
}
#endif


#if 0
// 练习6-12
void mat_mul(const int a[4][3],const int b[3][4],int c[3][3]){
    int i,j;
    for (i = 0 ; i < 4; i++) {
        for (j = 0 ; j < 3; i++) {
            c[j][i] = a[i][j] * b[j][i];
        }
    }
}
#endif


#if 0
// 练习6-14

int main(void)
{
    int a;
    static double s[5];
    
    for (a = 0; a < 5; a++)
        printf("s[%d] = %.1lf\n", a, s[a]);
    
    return 0;
 }
#endif


#if 0
// 练习6-15
 
void put_count(){
    static int a;
    
    a++;
    
    printf("put_coubt:第%d次\n",a);
}
 
int main(void)
{
    int a;
    
    for(a = 0; a < 3; a++)
        put_count();
    
    return 0;
}
#endif
